from database import WordDatabase
from ocr_helper import OCRHelper

def main():
    print("欢迎使用英语单词学习平台！")
    db = WordDatabase()
    ocr = OCRHelper()
    
    while True:
        print("\n请选择操作：")
        print("1. 上传图片识别单词")
        print("2. 查看所有已保存的单词")
        print("3. 退出")
        
        choice = input("请输入选项（1-3）：")
        
        if choice == "1":
            image_path = input("请输入图片路径：")
            words = ocr.extract_words_from_image(image_path)
            
            if words:
                added_count = db.add_words(words)
                print(f"\n成功识别 {len(words)} 个单词")
                print(f"新增 {added_count} 个单词到数据库")
                print("识别到的单词：", ", ".join(words))
            else:
                print("未能从图片中识别出单词，请确保图片清晰且包含英文文本。")
        
        elif choice == "2":
            words = db.get_all_words()
            if words:
                print("\n已保存的单词列表：")
                for i, word in enumerate(words, 1):
                    print(f"{i}. {word}")
            else:
                print("\n数据库中还没有保存任何单词。")
        
        elif choice == "3":
            print("感谢使用！再见！")
            break
        
        else:
            print("无效的选项，请重新选择。")

if __name__ == "__main__":
    main() 